package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.service.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * 全局降级处理
 * @author timiv
 */
@RestController
@DefaultProperties(defaultFallback = "global_paymentInfo_handle")
public class GlobalFallBackController {
    @Autowired
    private PaymentHystrixService paymentService;

    @GetMapping("/consumer/payment/hystrix/global/timeOut/{id}")
    @HystrixCommand
    public String payment_timeOut(@PathVariable("id") Integer id){
        int i = 10 / 0;
        return paymentService.payment_timeOut(id);
    };

    /**
     * 注意，此方法不能传参，和单一降级的方法有点区别
     * @return
     */
    public String global_paymentInfo_handle(){
        return "全局降级处理，/(ㄒoㄒ)/~~";
    }
}
